package com.kk.permission;

import android.accessibilityservice.AccessibilityService;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Build.VERSION;
import android.telecom.TelecomManager;
import android.text.TextUtils;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;

import com.kk.R;
import com.kk.permission.adapter.PermissionAdapter;
import com.kk.permission.handler.PermissionType;
import com.kk.permission.permissionlist.PermissionListUtil;
import com.kk.permission.usage.StatConst;
import com.kk.permission.utils.OSUtil;
import com.kk.permission.utils.PackageUtil;
import com.kk.permission.utils.PrefUtil;
import com.kk.permission.utils.callershow.CallerShowUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//import com.cootek.dialer.base.baseutil.thread.UiThreadExecutor;

//import com.cootek.module_callershow.util.BuildInfoUtil;

public abstract class IPermissionGuideStrategy {
    public static final List<String> EMPTY_PERMISSION_LIST = new ArrayList(0);
    public static final String PACKAGE_NAME_TEXT = "packageName";
    public static Map<String, String> PERMISSION_NAME_MAP = new HashMap<String, String>() {
        {
            put(GuideConst.TRUST_APPLICATION_PERMISSION_MIUI5, GuideConst.TRUST_APPLICATION_PERMISSION);
            put(GuideConst.MIUI_BACKGROUND_PROTECT_PERMISSION, GuideConst.BACKGROUND_PROTECT_PERMISSION);
            put(GuideConst.OPPO_BACKGROUND_FROZEN_PERMISSION, GuideConst.BACKGROUND_FROZEN_PERMISSION);
            put(GuideConst.OPPO_DOZE_PERMISSION, GuideConst.BACKGROUND_FROZEN_PERMISSION);
        }
    };
    public static final String PREF_KEY_DONE_PREFIX = "done_setted_";
    public static final String PREF_KEY_HALF_AUTO_DONE_PREFIX = "done_setted_half_auto";
    public static final String PREF_KEY_PREFIX = "setted_";
    public static final String PREF_KEY_RUN_PREFIX = "run_";
//    public static Map<String, String> SUB_TEXT_MAP = new HashMap<String, String>() {
//        {
//            put(GuideConst.DEFAULT_PERMISSION, ResUtils.getString(R.string.data_permission_main));
//            put(GuideConst.AUTOBOOT_PERMISSION, ResUtils.getString(R.string.autoboot_permission_sub_title));
//            put(GuideConst.AUTOBOOT_PERMISSION_2, ResUtils.getString(R.string.autoboot_permission_sub_title));
//            put(GuideConst.TRUST_APPLICATION_PERMISSION_MIUI5, "保障%s正常运行");
//            put(GuideConst.TRUST_APPLICATION_PERMISSION, ResUtils.getString(R.string.trust_application_permission_sub_title));
//            put(GuideConst.TOAST_PERMISSION, ResUtils.getString(R.string.toast_permission_sub_title));
//            put(GuideConst.BACKGROUND_PROTECT_PERMISSION, ResUtils.getString(R.string.background_protect_permission_sub_title));
//            put(GuideConst.MIUI_BACKGROUND_PROTECT_PERMISSION, ResUtils.getString(R.string.background_protect_permission_miui_sub_title));
//            put("notification", ResUtils.getString(R.string.permission_open_notification_sub_title));
//            put(GuideConst.CALL_PHONE_PERMISSION, "保证%s正常使用");
//            put(GuideConst.BACKGROUND_FROZEN_PERMISSION, "BACKGROUND_FROZEN_PERMISSION");
//            put(GuideConst.OPPO_BACKGROUND_FROZEN_PERMISSION, ResUtils.getString(R.string.background_frozen_permission_oppo_sub_title));
//            put(GuideConst.OPPO_DOZE_PERMISSION, ResUtils.getString(R.string.background_frozen_permission_oppo_sub_title));
//            put(GuideConst.BACKGROUND_RUNNING_PERMISSION, ResUtils.getString(R.string.background_frozen_permission_oppo_sub_title));
//            put(GuideConst.READ_CALLOG_PERMISSION, ResUtils.getString(R.string.read_call_log_permission_sub_title));
//            put(GuideConst.DONT_OPTIMIZE_POWER, ResUtils.getString(R.string.miuiv6_back_ground_saorao));
//            put(GuideConst.DOZE_PERMISSION, ResUtils.getString(R.string.doze_permission_sub_title));
//            put(GuideConst.READ_CONTACT_PERMISSION, ResUtils.getString(R.string.read_contact_permission_sub_title));
//            put(GuideConst.DIAL_NOTI_PERMISSION, ResUtils.getString(R.string.dial_noti_permission_sub_title));
//            put(GuideConst.CALL_RINGTONE_PERMISSION, ResUtils.getString(R.string.call_ringtone_permission_sub_title));
//            put(GuideConst.SHOW_IN_LOCKSCREEN_PERMISSION, ResUtils.getString(R.string.show_in_lockscreen_permission_sub_title));
//            put(GuideConst.BACK_SHOW_PERMISSION, ResUtils.getString(R.string.back_show_permission_sub_title));
//            put(GuideConst.ALLOW_NOTI_PERMISSION, ResUtils.getString(R.string.vivo_allow_noti_permission_sub_title));
//            put(GuideConst.INSTALL_SHORT_CUT, ResUtils.getString(R.string.allow_short_cut));
//            put(GuideConst.SYSTEM_DIALING_PERMISSION, ResUtils.getString(R.string.system_dialing_permission));
//        }
//    };
    public static final String changeNumStr = "system_dialer_change_num";
//    public static Map<String, String> mainTextMap = new HashMap<String, String>() {
//        {
//            put(GuideConst.DEFAULT_PERMISSION, ResUtils.getString(R.string.data_permission_main));
//            put(GuideConst.AUTOBOOT_PERMISSION, ResUtils.getString(R.string.autoboot_permission_main));
//            put(GuideConst.AUTOBOOT_PERMISSION_2, ResUtils.getString(R.string.autoboot_permission_main_2));
//            put(GuideConst.TRUST_APPLICATION_PERMISSION_MIUI5, "选择“信任%s");
//            put(GuideConst.TRUST_APPLICATION_PERMISSION_MIUI6, ResUtils.getString(R.string.trust_application_permission_main_miui6));
//            put(GuideConst.TRUST_APPLICATION_PERMISSION, ResUtils.getString(R.string.trust_application_permission_main));
//            put(GuideConst.DATA_PERMISSION, ResUtils.getString(R.string.data_permission_main));
//            put(GuideConst.TOAST_PERMISSION, ResUtils.getString(R.string.toast_permission_main));
//            put(GuideConst.TRUST_APPLICATION_PERMISSION_COOLPAD, ResUtils.getString(R.string.application_permission));
//            put(GuideConst.BACKGROUND_PROTECT_PERMISSION, ResUtils.getString(R.string.background_protect_permission_main));
//            put(GuideConst.MIUI_BACKGROUND_PROTECT_PERMISSION, ResUtils.getString(R.string.background_protect_permission_miui));
//            put(GuideConst.HUAWEI_V4_BACKGROUND_PROTECT_PERMISSION, ResUtils.getString(R.string.huawei_v4_background_protection_main));
//            put("white_list", ResUtils.getString(R.string.white_list_permission_main));
//            put(GuideConst.ZTE_WHITE_LIST, ResUtils.getString(R.string.white_list_permission_main_zte));
//            put(GuideConst.SMARTISION_BACKGROUND_PROTECT_PERMISSION, ResUtils.getString(R.string.smartision_background_protect_permission_main));
//            put("notification", ResUtils.getString(R.string.permission_open_notification));
//            put(GuideConst.CALL_PHONE_PERMISSION, "允许拨打电话");
//            put(GuideConst.BACKGROUND_FROZEN_PERMISSION, ResUtils.getString(R.string.background_frozen_permission_main));
//            put(GuideConst.OPPO_BACKGROUND_FROZEN_PERMISSION, ResUtils.getString(R.string.oppo_background_frozen_permission_main));
//            put(GuideConst.OPPO_DOZE_PERMISSION, ResUtils.getString(R.string.doze_permission_main));
//            put(GuideConst.BACKGROUND_RUNNING_PERMISSION, ResUtils.getString(R.string.oppo_background_runging_permission_main));
//            put(GuideConst.POWER_OPTIMIZATION, ResUtils.getString(R.string.samsung_power_optimization_main_title));
//            put(GuideConst.READ_CALLOG_PERMISSION, ResUtils.getString(R.string.read_call_log_permission_main));
//            put(GuideConst.DONT_OPTIMIZE_POWER, ResUtils.getString(R.string.miuiv6_back_ground));
//            put(GuideConst.DOZE_PERMISSION, ResUtils.getString(R.string.doze_permission_main));
//            put(GuideConst.READ_CONTACT_PERMISSION, ResUtils.getString(R.string.read_contact_permission_main));
//            put(GuideConst.DIAL_NOTI_PERMISSION, ResUtils.getString(R.string.dial_noti_permission_main));
//            put(GuideConst.CALL_RINGTONE_PERMISSION, ResUtils.getString(R.string.call_ringtone_permission));
//            put(GuideConst.SHOW_IN_LOCKSCREEN_PERMISSION, ResUtils.getString(R.string.show_in_lockscreen_permission));
//            put(GuideConst.BACK_SHOW_PERMISSION, ResUtils.getString(R.string.back_show_permission));
//            put(GuideConst.SYSTEM_DIALING_PERMISSION, ResUtils.getString(R.string.system_dialing_permission));
//        }
//    };
//    public static Map<String, Integer> statusMap = new HashMap<String, Integer>() {
//        {
//            put(GuideConst.AUTOBOOT_PERMISSION, Integer.valueOf(2));
//            put(GuideConst.AUTOBOOT_PERMISSION_2, Integer.valueOf(2));
//            put(GuideConst.DEFAULT_PERMISSION, Integer.valueOf(2));
//            put(GuideConst.DATA_PERMISSION, Integer.valueOf(8));
//            put(GuideConst.TRUST_APPLICATION_PERMISSION, Integer.valueOf(1));
//            put(GuideConst.TRUST_APPLICATION_PERMISSION_MIUI5, Integer.valueOf(1));
//            put(GuideConst.TRUST_APPLICATION_PERMISSION_MIUI6, Integer.valueOf(1));
//            put(GuideConst.TOAST_PERMISSION, Integer.valueOf(4));
//            put(GuideConst.TRUST_APPLICATION_PERMISSION_COOLPAD, Integer.valueOf(1));
//            put(GuideConst.BACKGROUND_PROTECT_PERMISSION, Integer.valueOf(16));
//            put(GuideConst.MIUI_BACKGROUND_PROTECT_PERMISSION, Integer.valueOf(16));
//            put(GuideConst.HUAWEI_V4_BACKGROUND_PROTECT_PERMISSION, Integer.valueOf(16));
//            put(GuideConst.MEIZU_WHITE_LIST, Integer.valueOf(32));
//            put(GuideConst.ZTE_WHITE_LIST, Integer.valueOf(32));
//            put("white_list", Integer.valueOf(32));
//            put(GuideConst.SMARTISION_BACKGROUND_PROTECT_PERMISSION, Integer.valueOf(16));
//            put("notification", Integer.valueOf(64));
//            put(GuideConst.CALL_PHONE_PERMISSION, Integer.valueOf(128));
//            put(GuideConst.BACKGROUND_FROZEN_PERMISSION, Integer.valueOf(256));
//            put(GuideConst.OPPO_BACKGROUND_FROZEN_PERMISSION, Integer.valueOf(256));
//            put(GuideConst.OPPO_DOZE_PERMISSION, Integer.valueOf(256));
//            put(GuideConst.READ_CALLOG_PERMISSION, Integer.valueOf(8));
//            put(GuideConst.READ_CONTACT_PERMISSION, Integer.valueOf(8));
//            put(GuideConst.DONT_OPTIMIZE_POWER, Integer.valueOf(256));
//            put(GuideConst.DOZE_PERMISSION, Integer.valueOf(2048));
//            put(GuideConst.BACKGROUND_RUNNING_PERMISSION, Integer.valueOf(16));
//            put(GuideConst.DIAL_NOTI_PERMISSION, Integer.valueOf(4096));
//            put(GuideConst.CALL_RINGTONE_PERMISSION, Integer.valueOf(8192));
//            put(GuideConst.SHOW_IN_LOCKSCREEN_PERMISSION, Integer.valueOf(16384));
//            put(GuideConst.BACK_SHOW_PERMISSION, Integer.valueOf(32768));
//            put(GuideConst.ALLOW_NOTI_PERMISSION, Integer.valueOf(65536));
//            put(GuideConst.INSTALL_SHORT_CUT, Integer.valueOf(131072));
//            put(GuideConst.SYSTEM_DIALING_PERMISSION, Integer.valueOf(262144));
//        }
//    };
    protected String currentPermission;
    public Context mContext = null;
    private WindowManager mWindowManager;

    protected void actionCallogOrContactPermission() {
    }

    protected void actionDataPermission() {
    }

    protected void actionPermissionDeny(int i) {
    }

    public void configAccessbility(AccessibilityService accessibilityService) {
    }

    public long estimatedSetupTime() {
        return 25000;
    }

//    protected PermissionGuideStepItem getPermissionGuideStepItem(String str, int i) {
//        return null;
//    }

    @Deprecated
    public ArrayList<String> getPermissionList(@PermissionType.PermissionTypeSpec int i) {
        return null;
    }

    protected String getPermissionTitle() {
        return "";
    }

    protected String getPermissionTitle(String str, int i) {
        return "";
    }

    public void handleAccessbilityEvent(AccessibilityEvent accessibilityEvent, AccessibilityService accessibilityService) {
    }

    protected boolean supportAutoPermission() {
        return true;
    }

    protected boolean supportGuide() {
        return true;
    }

    public IPermissionGuideStrategy(Context context) {
        this.mContext = context;
    }

    public boolean supportSecondGuide() {
        boolean z = false;
        if (!supportGuide()) {
            return false;
        }
        if (getPermissionList().size() > 0) {
            z = true;
        }
        return z;
    }

    protected void actionReadCalllog() {
        PrefUtil.setKey("setted_read_calllog_permission", true);
    }

    protected void actionReadContact() {
        PrefUtil.setKey("setted_read_contact_permission", true);
    }

    public boolean supportGuideExport() {
        return supportGuide();
    }

    protected void actionTrustApplicationPermission(boolean z) {
        PrefUtil.setKey("setted_background_protect_permission", true);
    }

    protected void actionAutoBootPermission() {
        this.currentPermission = GuideConst.AUTOBOOT_PERMISSION;
        PrefUtil.setKey("setted_autoboot_permission", true);
    }

    protected void actionShowInLockScreenPermission() {
        this.currentPermission = GuideConst.SHOW_IN_LOCKSCREEN_PERMISSION;
        PrefUtil.setKey("setted_show_in_lockscreen_permission", true);
    }

    protected void actionBackShowPermission() {
        this.currentPermission = GuideConst.BACK_SHOW_PERMISSION;
        PrefUtil.setKey("setted_back_show_permission", true);
    }

    protected void actionAllowNotiPermission() {
        this.currentPermission = GuideConst.ALLOW_NOTI_PERMISSION;
        PrefUtil.setKey("setted_allow_noti_permission", true);
    }

    protected void actionToastPermission() {
        this.currentPermission = GuideConst.TOAST_PERMISSION;
        PrefUtil.setKey("setted_toast_permission", true);
        CallerShowUtils.setFloatingWindowPermissionDefaultTag();
    }

    protected void actionDialNotiPermission() {
        this.currentPermission = GuideConst.DIAL_NOTI_PERMISSION;
        PrefUtil.setKey("setted_dial_noti_permission", true);
    }

    protected void actionCallRingtonePermission() {
        this.currentPermission = GuideConst.CALL_RINGTONE_PERMISSION;
        PrefUtil.setKey("setted_call_ringtone_permission", true);
    }

    protected void actionSystemDialingPermission() {
        this.currentPermission = GuideConst.SYSTEM_DIALING_PERMISSION;
        PrefUtil.setKey("setted_system_dialing_permission", true);
    }

    protected void actionOpenNotification() {
        this.currentPermission = "notification";
        PrefUtil.setKey("setted_notification", true);
    }

    protected void actionCallPhone() {
        this.currentPermission = GuideConst.CALL_PHONE_PERMISSION;
        PrefUtil.setKey("setted_call_phone_permission", true);
    }

    protected void actionBackgroundPermisssion() {
        this.currentPermission = GuideConst.BACKGROUND_PROTECT_PERMISSION;
        PrefUtil.setKey("setted_background_protect_permission_lock", true);
    }

    protected void actionPowerPermisssion() {
        this.currentPermission = GuideConst.DONT_OPTIMIZE_POWER;
        PrefUtil.setKey("setted_don_not_optimize_power", true);
    }

    protected void actionWhiteListPermisssion() {
        this.currentPermission = "white_list";
        PrefUtil.setKey("setted_white_list", true);
    }

    protected void actionBackgroundFrozenPermission() {
        this.currentPermission = GuideConst.BACKGROUND_FROZEN_PERMISSION;
        PrefUtil.setKey("setted_background_frozen_permission", true);
    }

    protected void actionBackgroundRuningPermission() {
        PrefUtil.setKey("setted_background_running_permission", true);
    }

    protected void actionDozePermission() {
        PrefUtil.setKey("setted_doze_permisison", true);
    }

    protected void actionInstallShortCut() {
        this.currentPermission = GuideConst.INSTALL_SHORT_CUT;
        PrefUtil.setKey("setted_install_short_cut", true);
    }

    protected int getColor() {
        return this.mContext.getResources().getColor(R.color.highlight_color);
    }

    protected int getPressedColor() {
        return this.mContext.getResources().getColor(R.color.highlight_color);
    }

    protected ArrayList<String> getSecondGuidePermissionList() {
        ArrayList<String> arrayList = new ArrayList();
        if (!supportGuide()) {
            return arrayList;
        }
        List<String> permissionList = getPermissionList();
        boolean isPackageInstalled = PackageUtil.isPackageInstalled(PackageUtil.OPPO_COLOROS_PERMISSION_SETTING_PACKAGE_NAMES);
        if (isPackageInstalled) {
            try {
                String[] split = Build.DISPLAY.split("_");
                if (Integer.parseInt(split[split.length - 1]) >= 170500) {
                    isPackageInstalled = false;
                }
            } catch (Exception unused) {
                for (String str : permissionList) {
                    StringBuilder stringBuilder;
                    String str2 = PERMISSION_NAME_MAP.containsKey(str) ? (String) PERMISSION_NAME_MAP.get(str) : str;
                    if (isPackageInstalled) {
                        stringBuilder = new StringBuilder();
                        stringBuilder.append(PREF_KEY_DONE_PREFIX);
                        stringBuilder.append(str2);
                        if (!PrefUtil.getKeyBoolean(stringBuilder.toString(), false)) {
                            arrayList.add(str);
                        }
                    }
                    stringBuilder = new StringBuilder();
                    stringBuilder.append(PREF_KEY_PREFIX);
                    stringBuilder.append(str2);
                    if (!PrefUtil.getKeyBoolean(stringBuilder.toString(), false)) {
                        arrayList.add(str);
                    }
                }
                for (String add : getPermissionList()) {
                    arrayList.add(add);
                }
                return arrayList;
            }
        }
        return arrayList;
    }

    public List<String> supportedPermissionList() {
        return PermissionListUtil.getAllOfPermissionNameList();
    }

    public List<String> getPermissionList() {
        return PermissionListUtil.getPermissionNameList();
    }

    public void generateButtonFunction(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("actionType = ");
        stringBuilder.append(str);
        setIsRun(str);
        if (GuideConst.AUTOBOOT_PERMISSION.equals(str) || GuideConst.AUTOBOOT_PERMISSION_2.equals(str)) {
            actionAutoBootPermission();
        } else if (GuideConst.READ_CALLOG_PERMISSION.equals(str)) {
            actionReadCalllog();
        } else if (GuideConst.READ_CONTACT_PERMISSION.equals(str)) {
            actionReadContact();
        } else if (GuideConst.TRUST_APPLICATION_PERMISSION.equals(str) || GuideConst.TRUST_APPLICATION_PERMISSION_MIUI5.equals(str) || GuideConst.TRUST_APPLICATION_PERMISSION_MIUI6.equals(str) || GuideConst.TRUST_APPLICATION_PERMISSION_COOLPAD.equals(str)) {
            actionTrustApplicationPermission(false);
        } else if (GuideConst.TOAST_PERMISSION.equals(str)) {
            actionToastPermission();
        } else if (GuideConst.DIAL_NOTI_PERMISSION.equals(str)) {
            actionDialNotiPermission();
        } else if (GuideConst.CALL_RINGTONE_PERMISSION.equals(str)) {
            actionCallRingtonePermission();
        } else if (GuideConst.SHOW_IN_LOCKSCREEN_PERMISSION.equals(str)) {
            actionShowInLockScreenPermission();
        } else if (GuideConst.BACK_SHOW_PERMISSION.equals(str)) {
            actionBackShowPermission();
        } else if (GuideConst.DATA_PERMISSION.equals(str)) {
            actionDataPermission();
        } else if (GuideConst.BACKGROUND_PROTECT_PERMISSION.equals(str) || GuideConst.MIUI_BACKGROUND_PROTECT_PERMISSION.equals(str) || GuideConst.SMARTISION_BACKGROUND_PROTECT_PERMISSION.equals(str) || GuideConst.HUAWEI_V4_BACKGROUND_PROTECT_PERMISSION.equals(str)) {
            actionBackgroundPermisssion();
        } else if (GuideConst.MEIZU_WHITE_LIST.equals(str) || "white_list".equals(str) || GuideConst.ZTE_WHITE_LIST.equals(str)) {
            actionWhiteListPermisssion();
        } else if ("notification".equals(str)) {
            actionOpenNotification();
        } else if (GuideConst.CALL_PHONE_PERMISSION.equals(str)) {
            actionCallPhone();
        } else if (GuideConst.BACKGROUND_FROZEN_PERMISSION.equals(str) || GuideConst.OPPO_BACKGROUND_FROZEN_PERMISSION.equals(str) || GuideConst.OPPO_DOZE_PERMISSION.equals(str)) {
            actionBackgroundFrozenPermission();
        } else if (GuideConst.BACKGROUND_RUNNING_PERMISSION.equals(str)) {
            actionBackgroundRuningPermission();
        } else if (GuideConst.DONT_OPTIMIZE_POWER.equals(str)) {
            actionPowerPermisssion();
        } else if (GuideConst.DOZE_PERMISSION.equals(str)) {
            actionDozePermission();
        } else if (GuideConst.INSTALL_SHORT_CUT.equals(str)) {
            actionInstallShortCut();
        } else if (GuideConst.ALLOW_NOTI_PERMISSION.equals(str)) {
            actionAllowNotiPermission();
        } else if (GuideConst.SYSTEM_DIALING_PERMISSION.equals(str)) {
            actionSystemDialingPermission();
        }
    }

    public boolean allOfTheGivenPermissionsSetted(List<String> list) {
        for (String str2 : list) {
            if (GuideConst.AUTOBOOT_PERMISSION.equals(str2) || GuideConst.AUTOBOOT_PERMISSION_2.equals(str2)) {
                str2 = GuideConst.AUTOBOOT_PERMISSION;
            } else if (GuideConst.TRUST_APPLICATION_PERMISSION.equals(str2) || GuideConst.TRUST_APPLICATION_PERMISSION_MIUI5.equals(str2) || GuideConst.TRUST_APPLICATION_PERMISSION_MIUI6.equals(str2) || GuideConst.TRUST_APPLICATION_PERMISSION_COOLPAD.equals(str2)) {
                str2 = GuideConst.TRUST_APPLICATION_PERMISSION;
            } else if (GuideConst.TOAST_PERMISSION.equals(str2)) {
                str2 = GuideConst.TOAST_PERMISSION;
            } else if (GuideConst.BACKGROUND_PROTECT_PERMISSION.equals(str2) || GuideConst.MIUI_BACKGROUND_PROTECT_PERMISSION.equals(str2) || GuideConst.SMARTISION_BACKGROUND_PROTECT_PERMISSION.equals(str2) || GuideConst.HUAWEI_V4_BACKGROUND_PROTECT_PERMISSION.equals(str2)) {
                str2 = GuideConst.BACKGROUND_PROTECT_PERMISSION;
            } else if (GuideConst.MEIZU_WHITE_LIST.equals(str2) || "white_list".equals(str2)) {
                str2 = "white_list";
            } else if (GuideConst.BACKGROUND_FROZEN_PERMISSION.equals(str2) || GuideConst.OPPO_BACKGROUND_FROZEN_PERMISSION.equals(str2) || GuideConst.OPPO_DOZE_PERMISSION.equals(str2)) {
                str2 = GuideConst.BACKGROUND_FROZEN_PERMISSION;
            }
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(PREF_KEY_PREFIX);
            stringBuilder.append(str2);
            if (!PrefUtil.getKeyBoolean(stringBuilder.toString(), false)) {
                return false;
            }
        }
        return true;
    }

    public boolean isHaveBackshowPermission() {
        List permissionList = getPermissionList();
        for (int i = 0; i < permissionList.size(); i++) {
            if (((String) permissionList.get(i)).equals(GuideConst.BACK_SHOW_PERMISSION)) {
                return true;
            }
        }
        return false;
    }

    public boolean getPermissionDone(String str) {
//        if (OSUtil.isVivo() && isHaveBackshowPermission() && !GuideConst.BACK_SHOW_PERMISSION.equals(str) && !VivoPermissionUtils.isBackgroundStartPermissionOpen(this.mContext)) {
//            return true;
//        }
        int obj = -1;
        switch (str) {
            case GuideConst.TOAST_PERMISSION:
                if (str.equals(GuideConst.TOAST_PERMISSION)) {
                    obj = -1;
                    break;
                }
                break;
            case GuideConst.CALL_RINGTONE_PERMISSION:
                if (str.equals(GuideConst.CALL_RINGTONE_PERMISSION)) {
                    obj = 2;
                    break;
                }
                break;
            case GuideConst.ALLOW_NOTI_PERMISSION:
                if (str.equals(GuideConst.ALLOW_NOTI_PERMISSION)) {
                    obj = 7;
                    break;
                }
                break;
            case GuideConst.TRUST_APPLICATION_PERMISSION:
                if (str.equals(GuideConst.TRUST_APPLICATION_PERMISSION)) {
                    obj = 5;
                    break;
                }
                break;
            case GuideConst.SHOW_IN_LOCKSCREEN_PERMISSION:
                if (str.equals(GuideConst.SHOW_IN_LOCKSCREEN_PERMISSION)) {
                    obj = 4;
                    break;
                }
                break;
            case GuideConst.DIAL_NOTI_PERMISSION:
                if (str.equals(GuideConst.DIAL_NOTI_PERMISSION)) {
                    obj = 1;
                    break;
                }
                break;
            case GuideConst.SYSTEM_DIALING_PERMISSION:
                if (str.equals(GuideConst.SYSTEM_DIALING_PERMISSION)) {
                    obj = 8;
                    break;
                }
                break;
            case GuideConst.INSTALL_SHORT_CUT:
                if (str.equals(GuideConst.INSTALL_SHORT_CUT)) {
                    obj = 6;
                    break;
                }
                break;
            case GuideConst.AUTOBOOT_PERMISSION:
                if (str.equals(GuideConst.AUTOBOOT_PERMISSION)) {
                    obj = 3;
                    break;
                }
                break;
        }
        switch (obj) {
            case -1:
                return CallerShowUtils.checkFloatingWindowPermission(this.mContext);
            case 1:
                return CallerShowUtils.checkNotificationSettingPermission(this.mContext);
            case 2:
                return CallerShowUtils.checkSysModifyPermission(this.mContext);
            case 3:
                return CallerShowUtils.checkAutoBootPermission();
            case 4:
                return CallerShowUtils.checkShowInLockScreenPermission();
            case 5:
                return CallerShowUtils.checkTurstApplicationPermission();
            case 6:
                return CallerShowUtils.checkInstallShortCutPermission();
            case 7:
                return CallerShowUtils.checkAllowNotiPermission();
            case 8:
                if (OSUtil.isVivo()) {
                    return true;
                }
                return CallerShowUtils.checkSystemDialingPermssion();
            default:
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(PREF_KEY_DONE_PREFIX);
                stringBuilder.append(str);
                return PrefUtil.getKeyBoolean(stringBuilder.toString(), false);
        }
    }

    public boolean getPermissionClick(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(PREF_KEY_PREFIX);
        stringBuilder.append(str);
        return PrefUtil.getKeyBoolean(stringBuilder.toString(), false);
    }

    public boolean enablePermission(List<String> list) {
        if (PackageUtil.isAutoPermission()) {
            return allPermissionEnable(list);
        }
        return allManaulPermissionSetted(list);
    }

    public boolean allManaulPermissionSetted(List<String> list) {
        if (list == null || list.size() == 0) {
            return true;
        }
        for (String permissionClick : list) {
            boolean permissionClick2 = getPermissionClick(permissionClick);
            if (!permissionClick2) {
                return permissionClick2;
            }
        }
        return true;
    }

    public boolean allPermissionEnable(List<String> list) {
        if (list == null || list.size() == 0) {
            return true;
        }
        for (String permissionDone : list) {
            boolean permissionDone2 = getPermissionDone(permissionDone);
            if (!permissionDone2) {
                return permissionDone2;
            }
        }
        return true;
    }

    public void clickAutoBootPermission() {
        actionAutoBootPermission();
    }

    public void clickPermissionDeny(int i) {
        actionPermissionDeny(i);
    }

    public void clickCalllogOrContactPermission() {
        actionCallogOrContactPermission();
    }

    public void clickBackgroundPermission() {
        actionBackgroundPermisssion();
    }

    public int accessbilityToastType() {
        return VERSION.SDK_INT >= 19 ? 2005 : 2002;
    }

//    protected void popupWindow(final View view, final Context context, long j) {
//        new Handler().post(new Runnable() {
//            @Override
//            public void run() {
//                final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//                final WindowManagerLinearLayout windowManagerLinearLayout = new WindowManagerLinearLayout(context);
//                try {
//                    windowManagerLinearLayout.addView(view, new LayoutParams(-1, -1));
//                } catch (Throwable unused) {
//                }
//            }
//        });
//        UiThreadExecutor.execute(new Runnable() {
//            public void run() {
//                final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//                final WindowManagerLinearLayout windowManagerLinearLayout = new WindowManagerLinearLayout(context);
//                try {
//                    windowManagerLinearLayout.addView(view, new LayoutParams(-1, -1));
//                } catch (Throwable unused) {
//                }
//            }
//        }, j);
//    }

    @SuppressLint("WrongConstant")
    public static boolean isChangeDefaultAppEnable() {
        Intent intent = new Intent();
        intent.setAction("android.telecom.action.CHANGE_DEFAULT_DIALER");
        intent.putExtra("android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME", PermissionAdapter.getAdapter().getAppContext().getPackageName());
        intent.setFlags(268435456);
        boolean z = intent.resolveActivity(PermissionAdapter.getAdapter().getAppContext().getPackageManager()) != null;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("is change default app enable : ");
        stringBuilder.append(z);
        return z;
    }

    @SuppressLint("WrongConstant")
    public static boolean isDefaultPhoneApp() {
        return VERSION.SDK_INT >= 23 ? TextUtils.equals(((TelecomManager) PermissionAdapter.getAdapter().getAppContext().getSystemService("telecom")).getDefaultDialerPackage(), PermissionAdapter.getAdapter().getAppContext().getPackageName()) : true;
    }

    @SuppressLint("WrongConstant")
    public static void setDefaultPhoneApp(boolean z) {
        if (VERSION.SDK_INT >= 23) {
            Intent intent = new Intent();
            intent.setAction("android.telecom.action.CHANGE_DEFAULT_DIALER");
            intent.putExtra("android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME", z ? PermissionAdapter.getAdapter().getAppContext().getPackageName() : getSystemDialer());
            intent.setFlags(268435456);
            PermissionAdapter.getAdapter().getAppContext().startActivity(intent);
        }
    }

    @SuppressLint("WrongConstant")
    public static void setDefaultPhoneApp(final Context context) {
        PrefUtil.setKey(changeNumStr, PrefUtil.getKeyInt(changeNumStr, 0) + 1);
        if (VERSION.SDK_INT < 23) {
            return;
        }
//        if (isDefaultPhoneApp()) {
//            final TDialog tDialog = new TDialog(context, 1);
//            View inflate = LayoutInflater.from(context).inflate(R.layout.dlg_system_dialing, null);
//            TextView textView = (TextView) inflate.findViewById(R.id.msg);
//            StringBuilder stringBuilder = new StringBuilder();
//            stringBuilder.append(ConfigHandler.getInstance().getAppName());
//            stringBuilder.append("已作为您的默认拨号应用");
//            textView.setText(stringBuilder.toString());
//            tDialog.setContentView(inflate);
//            tDialog.setTitle((CharSequence) "设置成功");
//            tDialog.setPositiveBtnText(R.string.ok);
//            tDialog.setOnPositiveBtnClickListener(new DialogInterface.OnClickListener() {
//                @Override
//                public void onClick(DialogInterface dialog, int which) {
//                    tDialog.dismiss();
//                    if (context instanceof PermissionGuideHalfAutoActivity) {
//                        ((PermissionGuideHalfAutoActivity) context).onRestart();
//                    }
//                }
//            });
//            if (context instanceof PermissionGuideHalfAutoActivity) {
//                ((PermissionGuideHalfAutoActivity) context).onPause();
//            }
//            tDialog.show();
//            return;
//        }
        PrefUtil.setKey("isDialer", true);
        PrefUtil.setKey("isChangePhone", true);
        Intent intent = new Intent();
        intent.setAction("android.telecom.action.CHANGE_DEFAULT_DIALER");
        intent.putExtra("android.telecom.extra.CHANGE_DEFAULT_DIALER_PACKAGE_NAME", PermissionAdapter.getAdapter().getAppContext().getPackageName());
        intent.setFlags(268435456);
        PermissionAdapter.getAdapter().getAppContext().startActivity(intent);
    }

    @SuppressLint("WrongConstant")
    private static String getSystemDialer() {
        if (VERSION.SDK_INT >= 23) {
            try {
                return (String) Class.forName("android.telecom.TelecomManager").getMethod("getSystemDialerPackage", (Class[]) null).invoke((TelecomManager) PermissionAdapter.getAdapter().getAppContext().getSystemService("telecom"), new Object[0]);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e2) {
                e2.printStackTrace();
            } catch (IllegalAccessException e3) {
                e3.printStackTrace();
            } catch (InvocationTargetException e4) {
                e4.printStackTrace();
            }
        }
        return null;
    }

    private void setIsRun(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(PREF_KEY_RUN_PREFIX);
        stringBuilder.append(str);
        PrefUtil.setKey(stringBuilder.toString(), "run");
    }

    public boolean startIntentActivities(Intent intent, String str, boolean z) {
        if (PrefUtil.getKeyBoolean("isAutomatic", false) != z) {
            PrefUtil.setKey("isAutomatic", z);
        }
        @SuppressLint("WrongConstant") List queryIntentActivities = this.mContext.getPackageManager().queryIntentActivities(intent, 65536);
        if (queryIntentActivities == null || queryIntentActivities.size() <= 0) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(PREF_KEY_DONE_PREFIX);
            stringBuilder.append(str);
            PrefUtil.setKey(stringBuilder.toString(), true);
            Map hashMap = new HashMap();
            hashMap.put("key_specific_permission_result", "2");
            hashMap.put("key_specific_permission_result", str);
            hashMap.put(StatConst.KEY_PERMISSION_AUTOMATIC, Boolean.valueOf(z));
            String str2;
            /*if (Build.MANUFACTURER.equalsIgnoreCase("vivo")) {
                VIVO_VERSION iVersion = VivoPermissionGuideStrategyBase.getIVersion();
                str2 = Build.MODEL;
                hashMap.put("version", iVersion);
                hashMap.put("model", str2);
            } else if (Build.MANUFACTURER.equalsIgnoreCase("oppo")) {
                try {
                    hashMap.put("model", Build.MODEL);
                    hashMap.put("version", this.mContext.getPackageManager().getPackageInfo(OppoColorOSPermissionGuideStrategy.OPPO_SAFECENTER, 0).versionName);
                } catch (Exception e) {
                    hashMap.put("version", VERSION.RELEASE);
                    e.printStackTrace();
                }
            } else*/ if (Build.MANUFACTURER.equalsIgnoreCase("huawei")) {
                str = Build.MODEL;
                str2 = VERSION.RELEASE;
                hashMap.put("model", str);
                hashMap.put("version", str2);
            } /*else if (Build.MANUFACTURER.equalsIgnoreCase("xiaomi")) {
                str = Build.MODEL;
                str2 = VERSION.RELEASE;
                hashMap.put("model", str);
                hashMap.put("version", str2);
            }
            StatRecorder.record(StatConst.KEY_PERMISSION_AUTOMATIC_TEST, hashMap);*/
            return false;
        }
        this.mContext.startActivity(intent);
        return true;
    }
}
